/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pscombine.extractor;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import pscombine.constants.Constants;

/**
 *
 * @author srkrishnan
 */
public class LangMap implements Constants {

    public static HashMap<Integer,Integer> generateLangMap(Connection dest, Connection src) {
        HashMap<Integer,Integer> langmap=new HashMap<Integer, Integer>();
        try {
            String query = "SELECT * FROM " + DB_PREFIX + "lang";

            Statement stcat = src.createStatement();

            ResultSet rs = stcat.executeQuery(query);

            while (rs.next()) {
//                System.out.println(rs.getInt("id_lang") + " -> " + rs.getString("iso_code"));

                String destquery = "SELECT * FROM " + DB_PREFIX + "lang where iso_code='"+rs.getString("iso_code")+"'";

                Statement destst = dest.createStatement();

                ResultSet destrs = destst.executeQuery(destquery);
                
                while(destrs.next()){
//                    System.out.println(destrs.getInt("id_lang") + " -> " + destrs.getString("iso_code"));
                    langmap.put(rs.getInt("id_lang"), destrs.getInt("id_lang"));
                }

            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return langmap;
    }
}
